<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 作用：可以在一个类上定义一个对象，那么实例化的对象就自动拥有了这个方法 -->
    <script>
        var arr = [1,2,3];
        
        Array.prototype.sum = function (arr) {
            let total = 0;
            for (let i = 0; i < arr.length; i++) {
                total += arr[i]
            }
            return total;
        }
        console.log(arr.sum(arr));
    </script>
</body>

</html>